Background : In the below code, there are 4 functions which jus checks for the Module's availablity and opens up the module in read only mode based on the Button click for 4 different tools which is corresponding to 4 different Modules.
Requirement: Since all the functions seem to be identical, except for the string name, can we have the 4 different functions to be merged into single funcctions so that we can remove the duplicated code.
// ============================================================== TAB NAMES ==============================================================
const string tabStrings[] = {"Type"}
DB mainDB
DBE theTab // MAIN TAB
DBE frameA // FRAMES
DBE ToolABtn, ToolBBtn, ToolCBtn, ToolDBtn // ELEMENTS (BUTTONS)
Skip tabASkip = create // SKIP FOR ELEMENTS ON FIRST TAB
Skip allTabsSkip = create // SKIP FOR ELEMENTS ON ALL TABS
int iKey
// -------------------------------------------------------------------------------------------------------------------------------------
// Tab callBack routine
void tabSelected(DBE tabDBE)
{ // Hide all DBEs and show the DBEs of the selected tab
int i = get tabDBE
Skip oneTabSkp
DBE dbe
for oneTabSkp in allTabsSkip do {for dbe in oneTabSkp do {hide dbe}}
if (find(allTabsSkip, i, oneTabSkp)){for dbe in oneTabSkp do {show dbe}}
} // Hide all DBEs and show the DBEs of the selected tab
// -------------------------------------------------------------------------------------------------------------------------------------
void closeDB__CallBack(DB db)
{ // Close dialogue box and delete skip lists
Skip s
for s in allTabsSkip do {delete s}
delete allTabsSkip
hide db
destroy db
db = null
} // Close dialogue box and delete skip lists
// -------------------------------------------------------------------------------------------------------------------------------------
// Create the DB and the tab strip
mainDB = create "New Requirement"
theTab = tab(mainDB, tabStrings, 500, 300, tabSelected)
// ============================================================== FIRST TAB =============================================================
iKey = 0
frameA = frame(mainDB, "Select the Tool", 120, 100)
// ============================================================== TOOL A =====================================================
full mainDB
void ToolABtn(DBE calledfrom)
{
string s = "/Admin/A"
if (exists module s)
{
Module myMod = current
int modAddr = (addr_ myMod)int
Module m = read("/Admin/A", true)
myMod = addr_ modAddr
current = myMod
}
else
{
errorBox "Missing Module '/Admin/A'"
}
}
// ============================================================== TOOL B =====================================================
void ToolBBtn(DBE calledfrom)
{
string s = "/Admin/B"
if (exists module s)
{
Module myMod = current
int modAddr = (addr_ myMod)int
Module m = read("/Admin/B", true)
myMod = addr_ modAddr
current = myMod
}
else
{
errorBox "Missing Module '/Admin/B'"
}
}
// ============================================================== TOOL C =====================================================
void ToolCBtn(DBE calledfrom)
{
string s = "/Admin/C"
if (exists module s)
{
Module myMod = current
int modAddr = (addr_ myMod)int
Module m = read("/Admin/C", true)
myMod = addr_ modAddr
current = myMod
}
else
{
errorBox "Missing Module '/Admin/C'"
}
}
// ============================================================== TOOL D =====================================================
void ToolDBtn(DBE calledfrom)
{
string s = "/Admin/D"
if (exists module s)
{
Module myMod = current
int modAddr = (addr_ myMod)int
Module m = read("/Admin/D", true)
myMod = addr_ modAddr
current = myMod
}
else
{
errorBox "Missing Module '/Admin/D'"
}
}
DBE ToolA = button(mainDB, "Tool A", ToolABtn)
DBE ToolB = button(mainDB, "Tool B", ToolBBtn)
DBE ToolC = button(mainDB, "Tool C", ToolCBtn)
DBE ToolD = button(mainDB, "Tool D", ToolDBtn)
// ============================================================== FIRST TAB DISPLAY =====================================================
put(tabASkip, iKey++, frameA)
put(tabASkip, iKey++, ToolA)
put(tabASkip, iKey++, ToolB)
put(tabASkip, iKey++, ToolC)
put(tabASkip, iKey++, ToolD)
// -------------------------------------------------------------------------------------------------------------------------------------
// Store the tab-specific Skip lists in the main tab Skip list
iKey = 0
put(allTabsSkip, iKey++, tabASkip)
// Add the close buton call-back which deletes the Skip lists
close(mainDB, true, closeDB__CallBack)
// Position the DBEs
// The tab strip is straight forward
theTab->"left" ->"form"
theTab->"right" ->"form"
theTab->"top" ->"form"
theTab->"bottom"->"form"
// ============================================================== FRAME DISPLAY =========================================================
// All frames are completely inside the tab
frameA->"left" ->"inside"->theTab
frameA->"right" ->"inside"->theTab
frameA->"top" ->"inside"->theTab
frameA->"bottom"->"inside"->theTab
ToolA->"top" ->"unattached"
ToolA->"top" ->"inside"->frameA
ToolA->"left" ->"form"
ToolA->"right" ->"unattached"
ToolA->"bottom"->"unattached"
ToolB->"top" ->"inside"->frameA
ToolB->"left" ->"spaced"->ToolA
ToolB->"right" ->"unattached"
ToolB->"bottom"->"unattached"
ToolC->"top" ->"inside"->frameA
ToolC->"left" ->"spaced"->ToolB
ToolC->"right" ->"unattached"
ToolC->"bottom"->"unattached"
ToolD->"top" ->"inside"->frameA
ToolD->"left" ->"spaced"->ToolC
ToolD->"right" ->"unattached"
ToolD->"bottom"->"unattached"
realize mainDB
tabSelected(theTab)
show mainDB
HKrishnan - Fri Nov 20 01:43:11 EST 2015 |
Re: Merge multiple Similar functions into 1 You got two options: a) Use the same callback for all buttons. Check the "calledFrom" parameter. The callback functions will get the button passed to them. b) Factor the common code out to a single function, but keep the 4 callbacks. I would go with b) so the logic does not need to know about the GUI elements.
void DoWork (string modName) {
if (exists module modName)
{
Module myMod = current
// int modAddr = (addr_ myMod)int // ??
Module m = read(modName, true)
// myMod = addr_ modAddr // ??
current = myMod
}
else
{
errorBox "Missing Module " modName
}
}
void ToolABtn(DBE calledfrom) { DoWork ("/MyModule/A")}
void ToolBBtn(DBE calledfrom) { DoWork ("/MyModule/B")}
void ToolCBtn(DBE calledfrom) { DoWork ("/MyModule/C")}
void ToolDBtn(DBE calledfrom) { DoWork ("/MyModule/D")}
Hope this helps, regards, Mathias |
Re: Merge multiple Similar functions into 1 Similary can we have the below generalised as well ?
//========================================================================================================================================
// ============================================================== TAB NAMES ==============================================================
//========================================================================================================================================
const string tabStrings[] = {"Type"}
DB mainDB
DBE theTab // MAIN TAB
DBE frameA // FRAMES
DBE ToolABtn, ToolBBtn, ToolCBtn, ToolDBtn // ELEMENTS (BUTTONS)
Skip tabASkip = create // SKIP FOR ELEMENTS ON FIRST TAB
Skip allTabsSkip = create // SKIP FOR ELEMENTS ON ALL TABS
int iKey
// -------------------------------------------------------------------------------------------------------------------------------------
// Tab callBack routine
void tabSelected(DBE tabDBE)
{ // Hide all DBEs and show the DBEs of the selected tab
int i = get tabDBE
Skip oneTabSkp
DBE dbe
for oneTabSkp in allTabsSkip do {for dbe in oneTabSkp do {hide dbe}}
if (find(allTabsSkip, i, oneTabSkp)){for dbe in oneTabSkp do {show dbe}}
} // Hide all DBEs and show the DBEs of the selected tab
// -------------------------------------------------------------------------------------------------------------------------------------
void closeDB__CallBack(DB db)
{ // Close dialogue box and delete skip lists
Skip s
for s in allTabsSkip do {delete s}
delete allTabsSkip
hide db
destroy db
db = null
} // Close dialogue box and delete skip lists
// -------------------------------------------------------------------------------------------------------------------------------------
// Create the DB and the tab strip
mainDB = create "New Requirement"
theTab = tab(mainDB, tabStrings, 500, 300, tabSelected)
// ============================================================== FIRST TAB =============================================================
iKey = 0
frameA = frame(mainDB, "Select the Tool", 120, 100)
// ============================================================== TOOL A =====================================================
full mainDB
void ToolABtn(DBE calledfrom)
{
string s = "/Admin/A"
if (exists module s)
{
Module m = current
string targetModuleString = fullName(m)
string sourceModuleString = "/Admin/A"
Module sourceModule = read(sourceModuleString, false)
Module targetModuleM = edit targetModuleString
current = targetModuleM
Object currSourceObject = first sourceModule
string currObjHeading = currSourceObject."Object Heading"
Object currObj = current Object
Object parObj = parent currObj
string strngToMatchParent = "HMI Requirements$"
string strngToMatchType = "Heading"
string strngToMatchCurrentObj = "AAA"
if ((level(currObj) > 1) && (matches(strngToMatchType, currObj."Requirement Type""") && (matches(strngToMatchParent, parObj."Object Heading""") && (matches(strngToMatchCurrentObj, currObj."Object Heading""" )))))
{
void copyObjects(Object currSourceObj, string objectNumber)
{
string currObjHeading = currSourceObj."Object Heading"
Module targetModule = current
Object firstObj = current targetModule
Object newoCSF
if(firstObj == null)
{
newoCSF = (Object create targetModule)
}
else
{
string firstObjHeading = firstObj."Object Heading"
string firstObjText = firstObj."Object Text"
newoCSF = create below firstObj
string newoDSFHeading = newoCSF."Object Heading"
}
newoCSF."Object Heading" = currObjHeading
}
copyObjects(currSourceObject, number(currSourceObject))
void getChildObjects(Object currObject)
{
Object childObj = next currObject
if(childObj != null)
{
string childObjectHeading = childObj."Object Heading"
string parentObjectHeading = currObject."Object Heading"
string childObjectText = childObj."Object Text"
string currObjText = currObject."Object Text"
string colonStr = " : "
string childObjectLevel = number(childObj)
string parentObjectLevel = number(currObject)
string childTopLevel = childObjectLevel[0:0]
string parentTopLevel = parentObjectLevel[0:0]
if(childTopLevel == parentTopLevel)
{
copyObjects(childObj, childObjectLevel)
getChildObjects(childObj)
}
}
}
getChildObjects(currSourceObject)
refresh(m)
infoBox "A in the current Module"
}
else
{
errorBox "Improper Selection.Please Select 'AAA' Header."
}
}
else
{
errorBox "Missing Module '/Admin/A'"
}
}
// ============================================================== TOOL B =====================================================
void ToolBBtn(DBE calledfrom)
{
string s = "/Admin/B"
if (exists module s)
{
Module m = current
string targetModuleString = fullName(m)
string sourceModuleString = "/Admin/B"
Module sourceModule = read(sourceModuleString, false)
Module targetModuleM = edit targetModuleString
current = targetModuleM
Object currSourceObject = first sourceModule
string currObjHeading = currSourceObject."Object Heading"
Object currObj = current Object
Object parObj = parent currObj
string strngToMatchParent = "HMI Requirements$"
string strngToMatchType = "Heading"
string strngToMatchCurrentObj = "BBB"
if ((level(currObj) > 1) && (matches(strngToMatchType, currObj."Requirement Type""") && (matches(strngToMatchParent, parObj."Object Heading""") && (matches(strngToMatchCurrentObj, currObj."Object Heading""" )))))
{
void copyObjects(Object currSourceObj, string objectNumber)
{
string currObjHeading = currSourceObj."Object Heading"
Module targetModule = current
Object firstObj = current targetModule
Object newoCSF
if(firstObj == null)
{
newoCSF = (Object create targetModule)
}
else
{
string firstObjHeading = firstObj."Object Heading"
string firstObjText = firstObj."Object Text"
newoCSF = create below firstObj
string newoDSFHeading = newoCSF."Object Heading"
}
newoCSF."Object Heading" = currObjHeading
}
copyObjects(currSourceObject, number(currSourceObject))
void getChildObjects(Object currObject)
{
Object childObj = next currObject
if(childObj != null)
{
string childObjectHeading = childObj."Object Heading"
string parentObjectHeading = currObject."Object Heading"
string childObjectText = childObj."Object Text"
string currObjText = currObject."Object Text"
string colonStr = " : "
string childObjectLevel = number(childObj)
string parentObjectLevel = number(currObject)
string childTopLevel = childObjectLevel[0:0]
string parentTopLevel = parentObjectLevel[0:0]
if(childTopLevel == parentTopLevel)
{
copyObjects(childObj, childObjectLevel)
getChildObjects(childObj)
}
}
}
getChildObjects(currSourceObject)
refresh(m)
infoBox "B in the current Module"
}
else
{
errorBox "Improper Selection.Please Select 'BBB' Header."
}
}
else
{
errorBox "Missing Module '/Admin/B'"
}
}
// ============================================================== TOOL C =====================================================
void ToolCBtn(DBE calledfrom)
{
string s = "/Admin/C"
if (exists module s)
{
Module m = current
string targetModuleString = fullName(m)
string sourceModuleString = "/Admin/C"
Module sourceModule = read(sourceModuleString, false)
Module targetModuleM = edit targetModuleString
current = targetModuleM
Object currSourceObject = first sourceModule
string currObjHeading = currSourceObject."Object Heading"
Object currObj = current Object
Object parObj = parent currObj
string strngToMatchParent = "HMI Requirements$"
string strngToMatchType = "Heading"
string strngToMatchCurrentObj = "CCC"
if ((level(currObj) > 1) && (matches(strngToMatchType, currObj."Requirement Type""") && (matches(strngToMatchParent, parObj."Object Heading""") && (matches(strngToMatchCurrentObj, currObj."Object Heading""" )))))
{
void copyObjects(Object currSourceObj, string objectNumber)
{
string currObjHeading = currSourceObj."Object Heading"
Module targetModule = current
Object firstObj = current targetModule
Object newoCSF
if(firstObj == null)
{
newoCSF = (Object create targetModule)
}
else
{
string firstObjHeading = firstObj."Object Heading"
string firstObjText = firstObj."Object Text"
newoCSF = create below firstObj
string newoDSFHeading = newoCSF."Object Heading"
}
newoCSF."Object Heading" = currObjHeading
}
copyObjects(currSourceObject, number(currSourceObject))
void getChildObjects(Object currObject)
{
Object childObj = next currObject
if(childObj != null)
{
string childObjectHeading = childObj."Object Heading"
string parentObjectHeading = currObject."Object Heading"
string childObjectText = childObj."Object Text"
string currObjText = currObject."Object Text"
string colonStr = " : "
string childObjectLevel = number(childObj)
string parentObjectLevel = number(currObject)
string childTopLevel = childObjectLevel[0:0]
string parentTopLevel = parentObjectLevel[0:0]
if(childTopLevel == parentTopLevel)
{
copyObjects(childObj, childObjectLevel)
getChildObjects(childObj)
}
}
}
getChildObjects(currSourceObject)
refresh(m)
infoBox "C in the current Module"
}
else
{
errorBox "Improper Selection.Please Select 'CCC' Header."
}
}
else
{
errorBox "Missing Module '/Admin/C'"
}
}
// ============================================================== TOOL D =====================================================
void ToolDBtn(DBE calledfrom)
{
string s = "/Admin/D"
if (exists module s)
{
Module m = current
string targetModuleString = fullName(m)
string sourceModuleString = "/Admin/D"
Module sourceModule = read(sourceModuleString, false)
Module targetModuleM = edit targetModuleString
current = targetModuleM
Object currSourceObject = first sourceModule
string currObjHeading = currSourceObject."Object Heading"
Object currObj = current Object
Object parObj = parent currObj
string strngToMatchParent = "HMI Requirements$"
string strngToMatchType = "Heading"
string strngToMatchCurrentObj = "DDD"
if ((level(currObj) > 1) && (matches(strngToMatchType, currObj."Requirement Type""") && (matches(strngToMatchParent, parObj."Object Heading""") && (matches(strngToMatchCurrentObj, currObj."Object Heading""" )))))
{
void copyObjects(Object currSourceObj, string objectNumber)
{
string currObjHeading = currSourceObj."Object Heading"
Module targetModule = current
Object firstObj = current targetModule
Object newoCSF
if(firstObj == null)
{
newoCSF = (Object create targetModule)
}
else
{
string firstObjHeading = firstObj."Object Heading"
string firstObjText = firstObj."Object Text"
newoCSF = create below firstObj
string newoDSFHeading = newoCSF."Object Heading"
}
newoCSF."Object Heading" = currObjHeading
}
copyObjects(currSourceObject, number(currSourceObject))
void getChildObjects(Object currObject)
{
Object childObj = next currObject
if(childObj != null)
{
string childObjectHeading = childObj."Object Heading"
string parentObjectHeading = currObject."Object Heading"
string childObjectText = childObj."Object Text"
string currObjText = currObject."Object Text"
string colonStr = " : "
string childObjectLevel = number(childObj)
string parentObjectLevel = number(currObject)
string childTopLevel = childObjectLevel[0:0]
string parentTopLevel = parentObjectLevel[0:0]
if(childTopLevel == parentTopLevel)
{
copyObjects(childObj, childObjectLevel)
getChildObjects(childObj)
}
}
}
getChildObjects(currSourceObject)
refresh(m)
infoBox "D in the current Module"
}
else
{
errorBox "Improper Selection.Please Select 'DDD' Header."
}
}
else
{
errorBox "Missing Module '/Admin/D'"
}
}
DBE ToolA = button(mainDB, "Tool A", ToolABtn)
DBE ToolB = button(mainDB, "Tool B", ToolBBtn)
DBE ToolC = button(mainDB, "Tool C", ToolCBtn)
DBE ToolD = button(mainDB, "Tool D", ToolDBtn)
// ============================================================== FIRST TAB DISPLAY =====================================================
put(tabASkip, iKey++, frameA)
put(tabASkip, iKey++, ToolA)
put(tabASkip, iKey++, ToolB)
put(tabASkip, iKey++, ToolC)
put(tabASkip, iKey++, ToolD)
// -------------------------------------------------------------------------------------------------------------------------------------
// Store the tab-specific Skip lists in the main tab Skip list
iKey = 0
put(allTabsSkip, iKey++, tabASkip)
// Add the close buton call-back which deletes the Skip lists
close(mainDB, true, closeDB__CallBack)
// Position the DBEs
// The tab strip is straight forward
theTab->"left" ->"form"
theTab->"right" ->"form"
theTab->"top" ->"form"
theTab->"bottom"->"form"
// ============================================================== FRAME DISPLAY =========================================================
// All frames are completely inside the tab
frameA->"left" ->"inside"->theTab
frameA->"right" ->"inside"->theTab
frameA->"top" ->"inside"->theTab
frameA->"bottom"->"inside"->theTab
ToolA->"top" ->"unattached"
ToolA->"top" ->"inside"->frameA
ToolA->"left" ->"form"
ToolA->"right" ->"unattached"
ToolA->"bottom"->"unattached"
ToolB->"top" ->"inside"->frameA
ToolB->"left" ->"spaced"->ToolA
ToolB->"right" ->"unattached"
ToolB->"bottom"->"unattached"
ToolC->"top" ->"inside"->frameA
ToolC->"left" ->"spaced"->ToolB
ToolC->"right" ->"unattached"
ToolC->"bottom"->"unattached"
ToolD->"top" ->"inside"->frameA
ToolD->"left" ->"spaced"->ToolC
ToolD->"right" ->"unattached"
ToolD->"bottom"->"unattached"
realize mainDB
tabSelected(theTab)
show mainDB
|
Re: Merge multiple Similar functions into 1 HKrishnan - Fri Nov 20 04:59:05 EST 2015 Similary can we have the below generalised as well ?
//========================================================================================================================================
// ============================================================== TAB NAMES ==============================================================
//========================================================================================================================================
const string tabStrings[] = {"Type"}
DB mainDB
DBE theTab // MAIN TAB
DBE frameA // FRAMES
DBE ToolABtn, ToolBBtn, ToolCBtn, ToolDBtn // ELEMENTS (BUTTONS)
Skip tabASkip = create // SKIP FOR ELEMENTS ON FIRST TAB
Skip allTabsSkip = create // SKIP FOR ELEMENTS ON ALL TABS
int iKey
// -------------------------------------------------------------------------------------------------------------------------------------
// Tab callBack routine
void tabSelected(DBE tabDBE)
{ // Hide all DBEs and show the DBEs of the selected tab
int i = get tabDBE
Skip oneTabSkp
DBE dbe
for oneTabSkp in allTabsSkip do {for dbe in oneTabSkp do {hide dbe}}
if (find(allTabsSkip, i, oneTabSkp)){for dbe in oneTabSkp do {show dbe}}
} // Hide all DBEs and show the DBEs of the selected tab
// -------------------------------------------------------------------------------------------------------------------------------------
void closeDB__CallBack(DB db)
{ // Close dialogue box and delete skip lists
Skip s
for s in allTabsSkip do {delete s}
delete allTabsSkip
hide db
destroy db
db = null
} // Close dialogue box and delete skip lists
// -------------------------------------------------------------------------------------------------------------------------------------
// Create the DB and the tab strip
mainDB = create "New Requirement"
theTab = tab(mainDB, tabStrings, 500, 300, tabSelected)
// ============================================================== FIRST TAB =============================================================
iKey = 0
frameA = frame(mainDB, "Select the Tool", 120, 100)
// ============================================================== TOOL A =====================================================
full mainDB
void ToolABtn(DBE calledfrom)
{
string s = "/Admin/A"
if (exists module s)
{
Module m = current
string targetModuleString = fullName(m)
string sourceModuleString = "/Admin/A"
Module sourceModule = read(sourceModuleString, false)
Module targetModuleM = edit targetModuleString
current = targetModuleM
Object currSourceObject = first sourceModule
string currObjHeading = currSourceObject."Object Heading"
Object currObj = current Object
Object parObj = parent currObj
string strngToMatchParent = "HMI Requirements$"
string strngToMatchType = "Heading"
string strngToMatchCurrentObj = "AAA"
if ((level(currObj) > 1) && (matches(strngToMatchType, currObj."Requirement Type""") && (matches(strngToMatchParent, parObj."Object Heading""") && (matches(strngToMatchCurrentObj, currObj."Object Heading""" )))))
{
void copyObjects(Object currSourceObj, string objectNumber)
{
string currObjHeading = currSourceObj."Object Heading"
Module targetModule = current
Object firstObj = current targetModule
Object newoCSF
if(firstObj == null)
{
newoCSF = (Object create targetModule)
}
else
{
string firstObjHeading = firstObj."Object Heading"
string firstObjText = firstObj."Object Text"
newoCSF = create below firstObj
string newoDSFHeading = newoCSF."Object Heading"
}
newoCSF."Object Heading" = currObjHeading
}
copyObjects(currSourceObject, number(currSourceObject))
void getChildObjects(Object currObject)
{
Object childObj = next currObject
if(childObj != null)
{
string childObjectHeading = childObj."Object Heading"
string parentObjectHeading = currObject."Object Heading"
string childObjectText = childObj."Object Text"
string currObjText = currObject."Object Text"
string colonStr = " : "
string childObjectLevel = number(childObj)
string parentObjectLevel = number(currObject)
string childTopLevel = childObjectLevel[0:0]
string parentTopLevel = parentObjectLevel[0:0]
if(childTopLevel == parentTopLevel)
{
copyObjects(childObj, childObjectLevel)
getChildObjects(childObj)
}
}
}
getChildObjects(currSourceObject)
refresh(m)
infoBox "A in the current Module"
}
else
{
errorBox "Improper Selection.Please Select 'AAA' Header."
}
}
else
{
errorBox "Missing Module '/Admin/A'"
}
}
// ============================================================== TOOL B =====================================================
void ToolBBtn(DBE calledfrom)
{
string s = "/Admin/B"
if (exists module s)
{
Module m = current
string targetModuleString = fullName(m)
string sourceModuleString = "/Admin/B"
Module sourceModule = read(sourceModuleString, false)
Module targetModuleM = edit targetModuleString
current = targetModuleM
Object currSourceObject = first sourceModule
string currObjHeading = currSourceObject."Object Heading"
Object currObj = current Object
Object parObj = parent currObj
string strngToMatchParent = "HMI Requirements$"
string strngToMatchType = "Heading"
string strngToMatchCurrentObj = "BBB"
if ((level(currObj) > 1) && (matches(strngToMatchType, currObj."Requirement Type""") && (matches(strngToMatchParent, parObj."Object Heading""") && (matches(strngToMatchCurrentObj, currObj."Object Heading""" )))))
{
void copyObjects(Object currSourceObj, string objectNumber)
{
string currObjHeading = currSourceObj."Object Heading"
Module targetModule = current
Object firstObj = current targetModule
Object newoCSF
if(firstObj == null)
{
newoCSF = (Object create targetModule)
}
else
{
string firstObjHeading = firstObj."Object Heading"
string firstObjText = firstObj."Object Text"
newoCSF = create below firstObj
string newoDSFHeading = newoCSF."Object Heading"
}
newoCSF."Object Heading" = currObjHeading
}
copyObjects(currSourceObject, number(currSourceObject))
void getChildObjects(Object currObject)
{
Object childObj = next currObject
if(childObj != null)
{
string childObjectHeading = childObj."Object Heading"
string parentObjectHeading = currObject."Object Heading"
string childObjectText = childObj."Object Text"
string currObjText = currObject."Object Text"
string colonStr = " : "
string childObjectLevel = number(childObj)
string parentObjectLevel = number(currObject)
string childTopLevel = childObjectLevel[0:0]
string parentTopLevel = parentObjectLevel[0:0]
if(childTopLevel == parentTopLevel)
{
copyObjects(childObj, childObjectLevel)
getChildObjects(childObj)
}
}
}
getChildObjects(currSourceObject)
refresh(m)
infoBox "B in the current Module"
}
else
{
errorBox "Improper Selection.Please Select 'BBB' Header."
}
}
else
{
errorBox "Missing Module '/Admin/B'"
}
}
// ============================================================== TOOL C =====================================================
void ToolCBtn(DBE calledfrom)
{
string s = "/Admin/C"
if (exists module s)
{
Module m = current
string targetModuleString = fullName(m)
string sourceModuleString = "/Admin/C"
Module sourceModule = read(sourceModuleString, false)
Module targetModuleM = edit targetModuleString
current = targetModuleM
Object currSourceObject = first sourceModule
string currObjHeading = currSourceObject."Object Heading"
Object currObj = current Object
Object parObj = parent currObj
string strngToMatchParent = "HMI Requirements$"
string strngToMatchType = "Heading"
string strngToMatchCurrentObj = "CCC"
if ((level(currObj) > 1) && (matches(strngToMatchType, currObj."Requirement Type""") && (matches(strngToMatchParent, parObj."Object Heading""") && (matches(strngToMatchCurrentObj, currObj."Object Heading""" )))))
{
void copyObjects(Object currSourceObj, string objectNumber)
{
string currObjHeading = currSourceObj."Object Heading"
Module targetModule = current
Object firstObj = current targetModule
Object newoCSF
if(firstObj == null)
{
newoCSF = (Object create targetModule)
}
else
{
string firstObjHeading = firstObj."Object Heading"
string firstObjText = firstObj."Object Text"
newoCSF = create below firstObj
string newoDSFHeading = newoCSF."Object Heading"
}
newoCSF."Object Heading" = currObjHeading
}
copyObjects(currSourceObject, number(currSourceObject))
void getChildObjects(Object currObject)
{
Object childObj = next currObject
if(childObj != null)
{
string childObjectHeading = childObj."Object Heading"
string parentObjectHeading = currObject."Object Heading"
string childObjectText = childObj."Object Text"
string currObjText = currObject."Object Text"
string colonStr = " : "
string childObjectLevel = number(childObj)
string parentObjectLevel = number(currObject)
string childTopLevel = childObjectLevel[0:0]
string parentTopLevel = parentObjectLevel[0:0]
if(childTopLevel == parentTopLevel)
{
copyObjects(childObj, childObjectLevel)
getChildObjects(childObj)
}
}
}
getChildObjects(currSourceObject)
refresh(m)
infoBox "C in the current Module"
}
else
{
errorBox "Improper Selection.Please Select 'CCC' Header."
}
}
else
{
errorBox "Missing Module '/Admin/C'"
}
}
// ============================================================== TOOL D =====================================================
void ToolDBtn(DBE calledfrom)
{
string s = "/Admin/D"
if (exists module s)
{
Module m = current
string targetModuleString = fullName(m)
string sourceModuleString = "/Admin/D"
Module sourceModule = read(sourceModuleString, false)
Module targetModuleM = edit targetModuleString
current = targetModuleM
Object currSourceObject = first sourceModule
string currObjHeading = currSourceObject."Object Heading"
Object currObj = current Object
Object parObj = parent currObj
string strngToMatchParent = "HMI Requirements$"
string strngToMatchType = "Heading"
string strngToMatchCurrentObj = "DDD"
if ((level(currObj) > 1) && (matches(strngToMatchType, currObj."Requirement Type""") && (matches(strngToMatchParent, parObj."Object Heading""") && (matches(strngToMatchCurrentObj, currObj."Object Heading""" )))))
{
void copyObjects(Object currSourceObj, string objectNumber)
{
string currObjHeading = currSourceObj."Object Heading"
Module targetModule = current
Object firstObj = current targetModule
Object newoCSF
if(firstObj == null)
{
newoCSF = (Object create targetModule)
}
else
{
string firstObjHeading = firstObj."Object Heading"
string firstObjText = firstObj."Object Text"
newoCSF = create below firstObj
string newoDSFHeading = newoCSF."Object Heading"
}
newoCSF."Object Heading" = currObjHeading
}
copyObjects(currSourceObject, number(currSourceObject))
void getChildObjects(Object currObject)
{
Object childObj = next currObject
if(childObj != null)
{
string childObjectHeading = childObj."Object Heading"
string parentObjectHeading = currObject."Object Heading"
string childObjectText = childObj."Object Text"
string currObjText = currObject."Object Text"
string colonStr = " : "
string childObjectLevel = number(childObj)
string parentObjectLevel = number(currObject)
string childTopLevel = childObjectLevel[0:0]
string parentTopLevel = parentObjectLevel[0:0]
if(childTopLevel == parentTopLevel)
{
copyObjects(childObj, childObjectLevel)
getChildObjects(childObj)
}
}
}
getChildObjects(currSourceObject)
refresh(m)
infoBox "D in the current Module"
}
else
{
errorBox "Improper Selection.Please Select 'DDD' Header."
}
}
else
{
errorBox "Missing Module '/Admin/D'"
}
}
DBE ToolA = button(mainDB, "Tool A", ToolABtn)
DBE ToolB = button(mainDB, "Tool B", ToolBBtn)
DBE ToolC = button(mainDB, "Tool C", ToolCBtn)
DBE ToolD = button(mainDB, "Tool D", ToolDBtn)
// ============================================================== FIRST TAB DISPLAY =====================================================
put(tabASkip, iKey++, frameA)
put(tabASkip, iKey++, ToolA)
put(tabASkip, iKey++, ToolB)
put(tabASkip, iKey++, ToolC)
put(tabASkip, iKey++, ToolD)
// -------------------------------------------------------------------------------------------------------------------------------------
// Store the tab-specific Skip lists in the main tab Skip list
iKey = 0
put(allTabsSkip, iKey++, tabASkip)
// Add the close buton call-back which deletes the Skip lists
close(mainDB, true, closeDB__CallBack)
// Position the DBEs
// The tab strip is straight forward
theTab->"left" ->"form"
theTab->"right" ->"form"
theTab->"top" ->"form"
theTab->"bottom"->"form"
// ============================================================== FRAME DISPLAY =========================================================
// All frames are completely inside the tab
frameA->"left" ->"inside"->theTab
frameA->"right" ->"inside"->theTab
frameA->"top" ->"inside"->theTab
frameA->"bottom"->"inside"->theTab
ToolA->"top" ->"unattached"
ToolA->"top" ->"inside"->frameA
ToolA->"left" ->"form"
ToolA->"right" ->"unattached"
ToolA->"bottom"->"unattached"
ToolB->"top" ->"inside"->frameA
ToolB->"left" ->"spaced"->ToolA
ToolB->"right" ->"unattached"
ToolB->"bottom"->"unattached"
ToolC->"top" ->"inside"->frameA
ToolC->"left" ->"spaced"->ToolB
ToolC->"right" ->"unattached"
ToolC->"bottom"->"unattached"
ToolD->"top" ->"inside"->frameA
ToolD->"left" ->"spaced"->ToolC
ToolD->"right" ->"unattached"
ToolD->"bottom"->"unattached"
realize mainDB
tabSelected(theTab)
show mainDB
Is this question for real? Of course the answer is: Yes.
Unfortunately for that you would need to refactor that incredibly spaghetty long method (that nobody understands when trying to read the code) to a couple of more sensible, parametrized functions. I won't do it :-) You might want to hear what "uncle bob" (Robert Martin) says about 'clean code'... Regards, Mathias |
Re: Merge multiple Similar functions into 1 And please consider pasting 100+ lines of code as an attachment instead of inlining them. |
Re: Merge multiple Similar functions into 1 Thanks Mathias
My Bad.. Since am new to Forums, am learning all the posting options
Anyways you answered my concern. Will start a new post for my actual requirement and skip posting 1000s of lines |